﻿@model HWmanagementClient.Models.UserMessages
@{
    ViewBag.Title = "Üzenetek";
}
<script type="text/javascript">
    $(function () {

        $.ajax({
            type: "POST",
            contentType: "application/json",
            url: "/Message/AutoComplete",
            dataType: "json",
            async: false
        })
			.done(function (msg) {
			    $("#messagemodel_to").autocomplete({
			        source: msg
			    });
			});

        $("#tabs").tabs();

    });

    function seemessage(id) {
        $("table.messs").hide();
        $("table#" + id).show("slow");
        $($("tr." + id)[0]).removeClass("newmess");
        $("tr.messrow").removeClass("actualmess");
        $($("tr." + id)[0]).addClass("actualmess");
        $($($("tr." + id)[0]).children()[0]).html("");

        $.ajax({
            type: "POST",
            contentType: "application/json",
            url: "/Message/Readed/" + id,
            dataType: "json",
            async: true
        });
    }

    function seemessage2(id) {
        $("table.messs").hide();
        $("table#" + id).show("slow");
        $($("tr." + id)[0]).removeClass("newmess");
        $("tr.messrow").removeClass("actualmess");
        $($("tr." + id)[0]).addClass("actualmess");
        $($($("tr." + id)[0]).children()[0]).html("");
    }

    function insertelement(element) {
        $("#messagemodel_message").val($("#messagemodel_message").val() + element);
        $("#messagemodel_message").focus();
    }
</script>
<h2>
    Üzenetek</h2>
@if (ViewBag.Succeeded == true)
{
    <div class="ui-widget">
        <div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;">
            <p>
                <span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
                <strong>OK!</strong> A küldés sikeres volt.</p>
        </div>
    </div>
    <br />
    <br />
}
else if (ViewBag.Succeeded == false)
{
    <div class="ui-widget">
        <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
            <p>
                <span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
                <strong>HIBA!</strong> A küldés nem sikerült.</p>
        </div>
    </div>
    <br />
    <br />
}
<div id="tabs">
    <ul>
        <li><a href="#tabs-1">Beérkezett üzenetek</a></li>
        <li><a href="#tabs-2">Új üzenet írása</a></li>
        <li><a href="#tabs-3">Elküldött üzenetek</a></li>
    </ul>
    <div id="tabs-1" style="vertical-align: top !important;">
        <p>
            <table width="100%">
                <tr>
                    <td style="width: 300px">
                        <table width="100%">
                            @foreach (var item in Model.messages)
                            {
                                if (!item.isinbox)
                                {
                                    continue;
                                }
                                if (item.isread == 0)
                                {
                                <tr style="width: 300px;" class="newmess @item.ID messrow">
                                    <td>
                                        <font color="red">ÚJ!</font>
                                    </td>
                                    <td align="left">
                                        <p align="left" style="margin: 0px !important;">
                                            <strong>@item.from</strong></p>
                                        <p align="right" style="margin: 0px !important;">
                                            <em><a href="#" onclick="seemessage(@item.ID);">@item.subj</a></em></p>
                                    </td>
                                </tr>
                                
                                }
                                else
                                {
                                <tr style="width: 300px;" class="messrow @item.ID">
                                    <td>
                                    </td>
                                    <td align="left">
                                        <p align="left" style="margin: 0px !important;">
                                            <strong>@item.from</strong></p>
                                        <p align="right" style="margin: 0px !important;">
                                            <em><a href="#" onclick="seemessage(@item.ID);">@item.subj</a></em></p>
                                    </td>
                                </tr>
                                }
                            }
                        </table>
                    </td>
                    <td valign="top">
                        @foreach (var item in Model.messages)
                        {
                            if (!item.isinbox)
                            {
                                continue;
                            }
                            <table width="100%" id="@item.ID" class="messs"  style="display: none;">
                                <tr>
                                    <td>
                                        <font color="#0066ff">@Html.Raw(item.message)</font>
                                    </td>
                                </tr>
                            </table>
                        }
                    </td>
                </tr>
            </table>
        </p>
    </div>
    <div id="tabs-2">
        <p>
            @using (Html.BeginForm())
            {
                <div>
                    <fieldset>
                        <legend>Levél összeállítása</legend>
                        <div class="editor-label">
                            Feladó:
                        </div>
                        <div class="editor-field">
                            <p>@Model.userData.Item1 (@Model.userData.Item2)</p>
                        </div>
                        <div class="editor-label">
                            Címzett:
                        </div>
                        <div class="editor-field ui-widget">
                            @Html.TextBoxFor(m => m.messagemodel.to)
                        </div>
                        <div class="editor-label">
                            Tárgy:
                        </div>
                        <div class="editor-field">
                            @Html.TextBoxFor(m => m.messagemodel.subj)
                        </div>
                        <div class="editor-label">
                            Üzenet:<br />
                            <a href="#" onclick="insertelement('[nl]'); return false;" class="buttonclass" style="color: White;">
                                [nl]</a> Új sor<br />
                            <a href="#" onclick="insertelement('[b]'); return false;" class="buttonclass" style="color: White;">
                                [b]</a> <strong>Félkövér</strong> <a href="#" onclick="insertelement('[xb]'); return false;"
                                    class="buttonclass" style="color: White;">[xb]</a>
                            <br />
                            <a href="#" onclick="insertelement('[i]'); return false;" class="buttonclass" style="color: White;">
                                [i]</a> <em>Dőlt</em> <a href="#" onclick="insertelement('[xi]'); return false;"
                                    class="buttonclass" style="color: White;">[xi]</a>
                            <br />
                            <a href="#" onclick="insertelement('[u]'); return false;" class="buttonclass" style="color: White;">
                                [u]</a> <u>Aláhúzott</u> <a href="#" onclick="insertelement('[xu]'); return false;"
                                    class="buttonclass" style="color: White;">[xu]</a>
                            <br />
                        </div>
                        <div class="editor-field">
                            @Html.TextAreaFor(m => m.messagemodel.message)
                        </div>
                        <p>
                            <input type="submit" value="Küldés" />
                        </p>
                    </fieldset>
                </div>
            }
        </p>
    </div>
    <div id="tabs-3" style="vertical-align: top !important;">
        <p>
            <table width="100%">
                <tr>
                    <td style="width: 300px">
                        <table width="100%">
                            @foreach (var item in Model.messages)
                            {
                                if (item.isinbox)
                                {
                                    continue;
                                }
                                
                                <tr style="width: 300px;" class="messrow @item.ID">
                                    <td>
                                    </td>
                                    <td align="left">
                                        <p align="left" style="margin: 0px !important;">
                                            <strong>@item.to</strong></p>
                                        <p align="right" style="margin: 0px !important;">
                                            <em><a href="#" onclick="seemessage2(@item.ID);">@item.subj</a></em></p>
                                    </td>
                                </tr>
                                
                            }
                        </table>
                    </td>
                    <td valign="top">
                        @foreach (var item in Model.messages)
                        {
                            if (item.isinbox)
                            {
                                continue;
                            }
                            <table width="100%" id="@item.ID" class="messs"  style="display: none;">
                                <tr>
                                    <td>
                                        <font color="#0066ff">@Html.Raw(item.message)</font>
                                    </td>
                                </tr>
                            </table>
                        }
                    </td>
                </tr>
            </table>
        </p>
    </div>
</div>
